#ifndef PREF_NETWORK_H_
#define PREF_NETWORK_H_

#include "../widgets.h"
#include "p_widgets.h"
#include "p_icon.h"

#include "../gtkversion.h"

namespace gpyp {
namespace pref {

class Dialog;

class YPList : public ListView<YPCollection> {
  friend class PrefNetwork;
private:
  Application              &app_;
  Gtk::Window              &parent_;

  Gtk::CellRendererToggle   renderer_enable_;
  CellRendererIcon          renderer_icon_;
  Gtk::CellRendererText     renderer_name_;
  Gtk::CellRendererText     renderer_url_;
  CellRendererEncoding      renderer_encoding_;
  CellRendererYPType        renderer_type_;
  Gtk::CellRendererToggle   renderer_pcraw_proxy_;
#ifdef GTK_HAVE_CELL_RENDERER_SPIN
  Gtk::CellRendererSpin     renderer_reload_interval_;
#else
  Gtk::CellRendererText     renderer_reload_interval_;
#endif

  Gtk::TreeViewColumn       column_enable_;
  Gtk::TreeViewColumn       column_icon_;
  Gtk::TreeViewColumn       column_name_;
  Gtk::TreeViewColumn       column_url_;
  Gtk::TreeViewColumn       column_encoding_;
  Gtk::TreeViewColumn       column_type_;
  Gtk::TreeViewColumn       column_pcraw_proxy_;
  Gtk::TreeViewColumn       column_reload_interval_;

  void enable_on_cell_data(Gtk::CellRenderer *cell, const Gtk::TreeIter &iter);
  void icon_on_cell_data(Gtk::CellRenderer *cell, const Gtk::TreeIter &iter);
  void name_on_cell_data(Gtk::CellRenderer *cell, const Gtk::TreeIter &iter);
  void url_on_cell_data(Gtk::CellRenderer *cell, const Gtk::TreeIter &iter);
  void encoding_on_cell_data(Gtk::CellRenderer *cell, const Gtk::TreeIter &iter);
  void type_on_cell_data(Gtk::CellRenderer *cell, const Gtk::TreeIter &iter);
  void pcraw_proxy_on_cell_data(Gtk::CellRenderer *cell, const Gtk::TreeIter &iter);
  void reload_interval_on_cell_data(Gtk::CellRenderer *cell, const Gtk::TreeIter &iter);

  void enable_on_toggled(const Glib::ustring &path);
  void icon_on_edited(const Glib::ustring &path, const Glib::ustring &new_icon_name);
  void name_on_edited(const Glib::ustring &path, const Glib::ustring &new_text);
  void url_on_edited(const Glib::ustring &path, const Glib::ustring &new_text);
  void encoding_on_edited(const Glib::ustring &path, const Glib::ustring &new_text);
  void type_on_changed(const Glib::ustring &path, YPType type);
  void pcraw_proxy_on_toggled(const Glib::ustring &path);
  void reload_interval_on_edited(const Glib::ustring &path, const Glib::ustring &new_text);

public:
  void add_favorite();

  YPList(Application &app, Gtk::Window &parent);
};

class Network : public Gtk::VBox {
private:
  Application      &app_;

  HostEntry         peercast_server_;
  Gtk::Entry        peercast_server_id_;
  Gtk::Entry        peercast_server_pw_;
  HostEntry         pcraw_proxy_server_;
  Gtk::Entry        useragent_;
  Gtk::SpinButton   timeout_;
  Gtk::SpinButton   autoretry_limit_;
  Gtk::SpinButton   autoretry_interval_;
  Gtk::CheckButton  disable_ipv6_;

  Gtk::SpinButton   time_keep_ended_;
  Gtk::CheckButton  use_cache_;

  YPList            yplist_;

  autoconn          conn_ua_changed_;

protected:
  void ua_on_changed();

public:
  Network(Application &app, Gtk::Window &parent);
};

}/*pref*/
}/*gpyp*/

#endif/*PREF_NETWORK_H_*/
